#define  _CRT_SECURE_NO_WARNINGS
#include"Fixed_length_ pool.h"
#include"CentralCache.h"
#include "CurrenAlloc.h"

void Alloc1()
{
	for (size_t i = 0; i < 5; ++i)
	{
		void* ptr = CurrentAlloc(6);
	}
}

void Alloc2()
{
	for (size_t i = 0; i < 5; ++i)
	{
		void* ptr = CurrentAlloc(7);
	}
}

void TLSTest()
{
	std::thread t1(Alloc1);
	t1.join();

	std::thread t2(Alloc2);
	t2.join();
}

void TestCurrentAlloc1()
{
	void* p1 = CurrentAlloc(6);
	void* p2 = CurrentAlloc(8);
	void* p3 = CurrentAlloc(1);
	void* p4 = CurrentAlloc(7);
	void* p5 = CurrentAlloc(8);

	cout << p1 << endl;
	cout << p2 << endl;
	cout << p3 << endl;
	cout << p4 << endl;
	cout << p5 << endl;
}

void TestCurrentAlloc2()
{
	for (size_t i = 0; i < 1024; ++i)
	{
		void* p1 = CurrentAlloc(6);
		cout << p1 << endl;
	}

	void* p2 = CurrentAlloc(8);
	cout << p2 << endl;
}

void TestCurrentAlloc3()
{
	 
	void* p1 = CurrentAlloc(6);
	void* p2 = CurrentAlloc(6);
	void* p3 = CurrentAlloc(6);
	void* p4 = CurrentAlloc(6);
	cout << p1 << endl;
	cout << p2 << endl;
	cout << p3 << endl;
	cout << p4 << endl;
	CurrentDealloc(p1 );
	CurrentDealloc(p2 );
	CurrentDealloc(p3 );
	CurrentDealloc(p4 );
}

void MultiThreadAlloc1()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 7; ++i)
	{
		void* ptr = CurrentAlloc(16);
		v.push_back(ptr);
	}

	for (auto e : v)
	{
		CurrentDealloc(e );
	}
}

void MultiThreadAlloc2()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 7; ++i)
	{
		void* ptr = CurrentAlloc(16);
		v.push_back(ptr);
	}

	for (auto e : v)
	{
		CurrentDealloc(e );
	}
}

void TestMultiThread()
{
	std::thread t1(MultiThreadAlloc1);
	std::thread t2(MultiThreadAlloc2);

	t1.join();
	t2.join();
}

void BigAlloc()
{
	void* p1 = CurrentAlloc(257 * 1024);
	CurrentDealloc(p1);

	void* p2 = CurrentAlloc(129 * 8 * 1024);
	CurrentDealloc(p2);
}

//int main()
//{
//	 
//	BigAlloc();
//	return 0;
//}